<?php

ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_NOTICE);
date_default_timezone_set('Asia/Shanghai');
header("Content-Type:text/html; charset=utf-8");



?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Redis首页<?php echo $type?></title>
<script type="text/javascript" src="js/ajax141212.js"></script>
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<style>
body,h1,h2,h3,h4,h5,h6,hr,p,dl,dt,dd,ul,ol,li,pre,form,button,input,textarea,th,td {margin:0;padding:0;}
body,button,input,select,textarea {font:12px;}
ul,ol,li{list-style:none;}
img{ border:0; vertical-align:top;}
.w50{ width:50px;}

.examdiv li{
	margin:0px auto; 
	width:1000px;
	margin-bottom:20px;
}

.examdiv .php{
	color: #ff3a00;
	font-weight:bold;
}

.examdiv .param{
	color: #2a00ff;

}

</style>
</head>
<body>
<?php $this->load->view("layout/topinfo");?>
<br>
<div style="margin:0 auto; width:1000px;">
  
  类型：<select id="type" name="type">
    <option value="0"<?= ($type==0) ? ' selected="selected"' : ''?>>全部类型</option>
    <option value="1"<?= ($type==1) ? ' selected="selected"' : ''?>>String 字符串</option>
    <option value="2"<?= ($type==2) ? ' selected="selected"' : ''?>>Set 无序集合</option>
    <option value="3"<?= ($type==3) ? ' selected="selected"' : ''?>>List 列表</option>
    <option value="4"<?= ($type==4) ? ' selected="selected"' : ''?>>Zset 有序集合</option>
    <option value="5"<?= ($type==5) ? ' selected="selected"' : ''?>>Hash 哈希表</option>
  </select> key：<input id="key" name="key" type="text" value="<?php echo $key?>" style="width:100px;"/>　
  <input id="search_buttion" type="button" value="查询"/>
</div>

<table align="center" width="1000" border="1" style="margin-top:10px;">
  <tr bgcolor="#CCCCCC">
    <td>KEY</td>
    <td>TYPE</td>
    <td>LIFE</td>
    <td align="center">操作</td>
  </tr>
<?php

	for($i=$pageinfo->offset, $j=0; $j<$pageinfo->limit; $i++, $j++){
		
		$tempkey = $alldata[$i];
		
		if($redis->type($tempkey) == 1){
?>
  <tr>
    <td><?php echo $tempkey?></td>
    <td>string(字符串)</td>
    <td><?php echo $redis->ttl($tempkey)?></td>
    <td align="center"><input type="button" value="查看" onclick="(function(){window.open('/str?key=<?php echo urlencode($tempkey)?>')})()"/> 
    <input type="button" value="删除" onclick="del('<?php echo $tempkey?>')"/></td>
  </tr>
<?php
		}else if($redis->type($tempkey) == 2){
?>
  <tr>
    <td><?php echo $tempkey?></td>
    <td>set(无序集合)</td>
    <td><?php echo $redis->ttl($tempkey)?></td>
    <td align="center"><input type="button" value="查看" onclick="(function(){window.open('type-set.php?key=<?php echo urlencode($tempkey)?>')})()"/>  
    <input type="button" value="删除" onclick="del('<?php echo $tempkey?>')"/>
    </td>
  </tr>
<?php
		}else if($redis->type($tempkey) == 3){
?>
  <tr>
    <td><?php echo $tempkey?></td>
    <td>list(列表)</td>
    <td><?php echo $redis->ttl($tempkey)?></td>
    <td align="center"><input type="button" value="查看" onclick="(function(){window.open('/typeList.html?key=<?php echo urlencode($tempkey)?>')})()"/> 
    <input type="button" value="删除" onclick="del('<?php echo $tempkey?>')"/></td>
  </tr>
<?php
		}else if($redis->type($tempkey) == 4){
?>
  <tr>
    <td><?php echo $tempkey?></td>
    <td>zset(有序集合)</td>
    <td><?php echo $redis->ttl($tempkey)?></td>
    <td align="center"><input type="button" value="查看" onclick="(function(){window.open('type-zset.php?key=<?php echo urlencode($tempkey)?>')})()"/> 
    <input type="button" value="删除" onclick="del('<?php echo $tempkey?>')"/>
    </td>
  </tr>
<?php
		}else if($redis->type($tempkey) == 5){
?>
  <tr>
    <td><?php echo $tempkey?></td>
    <td>hash(哈希表)</td>
    <td><?php echo $redis->ttl($tempkey)?></td>
    <td align="center"><input type="button" value="查看" onclick="(function(){window.open('type-hash.php?key=<?php echo urlencode($tempkey)?>')})()"/> 
    <input type="button" value="删除" onclick="del('<?php echo $tempkey?>')"/>
    </td>
  </tr>
<?php
		}
	}
?>
  <tr>
    <td colspan="4" align="center">
    数据总数：<?php echo $pageinfo->dataCount?>，
    页数：<?php echo $pageinfo->currentPage."/".$pageinfo->pageCount?> 
    <a href="?type=<?=$type?>&key=<?php echo $key?>&page=<?=$pageinfo->prevPage?>">上一页</a> 
    <a href="?type=<?=$type?>&key=<?php echo $key?>&page=<?=$pageinfo->nextPage?>">下一页</a></td>
  </tr>
</table>

<br>
<script language="javascript">

var url_params = <?php echo json_encode($url_params)?>;

console.log(url_params);

document.getElementById("search_buttion").onclick = function(){
	var type = document.getElementById("type").value;
	var key = document.getElementById("key").value;
	
	url_params.type = type;
	url_params.key = encodeURIComponent(key);
	
	var url = "";
	for(var key in url_params){
		url += '&'+ key +'='+ url_params[key];
    }
	url = '?'+url.substr(1);

	console.log(url);
	window.location.href = url;
}



function del(key){
	var request = new Ajax();
	if(confirm("确定删除KEY："+key+"？")){
		request.get({
			url : '/site/del?key='+encodeURIComponent(key),
			resultType : 'json',
			onLoaded : function(result){
				console.log(result);
				if(result.code == 1){
					window.location.reload();
				}else{
					alert(result.info);	
				}
			}
		});	
	}
}

function dbSize(obj){
	 new Ajax().get({
		url : 'action.php?action=dbSize',
		resultType : 'text',
		onLoaded : function(result){
			alert(result);
//			window.location.reload();
		}
	});
}

function rename(obj){

	var p1 = $(obj).parent().find('input')[0].value;
	var p2 = $(obj).parent().find('input')[1].value;
	 new Ajax().get({
		url : 'action.php?action=rename'+'&p1='+encodeURIComponent(p1)+'&p2='+encodeURIComponent(p2),
		resultType : 'text',
		onLoaded : function(result){
			alert(result);
			window.location.reload();
		}
	});	

}

function renameNx(obj){

	var p1 = $(obj).parent().find('input')[0].value;
	var p2 = $(obj).parent().find('input')[1].value;
	 new Ajax().get({
		url : 'action.php?action=renameNx'+'&p1='+encodeURIComponent(p1)+'&p2='+encodeURIComponent(p2),
		resultType : 'text',
		onLoaded : function(result){
			alert(result);
			window.location.reload();
		}
	});	

}

function redis_delete(obj){

	var p1 = $(obj).parent().find('input')[0].value;
	var request = new Ajax();
	if(confirm("确定删除KEY："+p1+"？")){
		request.get({
			url : 'action.php?action=redis_delete&p1='+encodeURIComponent(p1),
			resultType : 'text',
			onLoaded : function(result){
				alert(result);
				window.location.reload();
			}
		});	
	}
}

function ping(obj){
	new Ajax().get({
		url : 'action.php?action=ping',
		resultType : 'text',
		onLoaded : function(result){
			alert(result);
//			window.location.reload();
		}
	});
}

function info(obj){
	new Ajax().get({
		url : 'action.php?action=info',
		resultType : 'text',
		onLoaded : function(result){
			alert(result);
//			window.location.reload();
		}
	});
}



function move(obj){

	var p1 = $(obj).parent().find('input')[0].value;
	var p2 = $(obj).parent().find('input')[1].value;
	new Ajax().get({
		url : 'action.php?action=move'+'&p1='+encodeURIComponent(p1)+'&p2='+encodeURIComponent(p2),
		resultType : 'text',
		onLoaded : function(result){
			alert(result);
			window.location.reload();
		}
	});
	
}

function save(obj){
	new Ajax().get({
		url : 'action.php?action=save',
		resultType : 'text',
		onLoaded : function(result){
			alert(result);
//			window.location.reload();
		}
	});
}

function bgsave(obj){
	new Ajax().get({
		url : 'action.php?action=bgsave',
		resultType : 'text',
		onLoaded : function(result){
			alert(result);
//			window.location.reload();
		}
	});
}

function lastSave(obj){
	new Ajax().get({
		url : 'action.php?action=lastSave',
		resultType : 'text',
		onLoaded : function(result){
			alert(result);
//			window.location.reload();
		}
	});
}

function bgrewriteaof(obj){
	new Ajax().get({
		url : 'action.php?action=bgrewriteaof',
		resultType : 'text',
		onLoaded : function(result){
			alert(result);
//			window.location.reload();
		}
	});
}

function flushdb(obj){
	new Ajax().get({
		url : 'action.php?action=flushdb',
		resultType : 'text',
		onLoaded : function(result){
			alert(result);
			window.location.reload();
		}
	});
}

function expire(obj){

	var p1 = $(obj).parent().find('input')[0].value;
	var p2 = $(obj).parent().find('input')[1].value;
	new Ajax().get({
		url : 'action.php?action=expire'+'&p1='+encodeURIComponent(p1)+'&p2='+encodeURIComponent(p2),
		resultType : 'text',
		onLoaded : function(result){
			alert(result);
			window.location.reload();
		}
	});
	
}

function expireAt(obj){

	var p1 = $(obj).parent().find('input')[0].value;
	var p2 = $(obj).parent().find('input')[1].value;
	new Ajax().get({
		url : 'action.php?action=expireAt'+'&p1='+encodeURIComponent(p1)+'&p2='+encodeURIComponent(p2),
		resultType : 'text',
		onLoaded : function(result){
			alert(result);
			window.location.reload();
		}
	});
	
}

function persist(obj){

	var p1 = $(obj).parent().find('input')[0].value;
	new Ajax().get({
		url : 'action.php?action=persist'+'&p1='+encodeURIComponent(p1),
		resultType : 'text',
		onLoaded : function(result){
			alert(result);
			window.location.reload();
		}
	});
	
}

function exists(obj){
	var p1 = $(obj).parent().find('input')[0].value;
	new Ajax().get({
		url : 'action.php?action=exists'+'&p1='+encodeURIComponent(p1),
		resultType : 'text',
		onLoaded : function(result){
			alert(result);
			window.location.reload();
		}
	});
}

function randomKey(obj){
	new Ajax().get({
		url : 'action.php?action=randomKey',
		resultType : 'text',
		onLoaded : function(result){
			alert(result);
			window.location.reload();
		}
	});
}
</script>
</body>
</html>
